package com.candy.control;

import com.candy.bean.UserInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;
import java.util.List;
@Api(tags = "用户信息管理",value = "用户信息管理")
@Controller
public class ShowUserInfoController {
    /**
     * 获取用户信息
     */
    @ApiOperation("获取用户信息列表")
    @RequestMapping("/getUserInfoes")
    public ModelAndView getUserInfoes(){
        List<UserInfo> userInfos=new ArrayList<>();
        userInfos.add(new UserInfo(1001,"tom","123456","qingdao"));
        userInfos.add(new UserInfo(1002,"lily","123456","jinan"));
        userInfos.add(new UserInfo(1003,"tony","123456","zibo"));
        ModelAndView mv=new ModelAndView();
        mv.setViewName("userInfoManager");
        mv.addObject("users",userInfos);
        return mv;
    }
    @ApiOperation("根据用户信息获取用户")
    @ResponseBody
    @PostMapping("/getUserInfoById")
    public UserInfo getUserInfoes(@RequestBody UserInfo userInfo){
        System.out.println(userInfo);
        return userInfo;
    }
    @ApiOperation("根据用户id获取用户信息")
    @GetMapping("/selectUser/{userid}")
    @ResponseBody
    public UserInfo selectUserInfoById(@PathVariable("userid") int userid){
        System.out.println(userid);
        return  new UserInfo(1001,"tom","123456","qingdao");
    }

    @ApiOperation("用户信息更新")
    @PutMapping("/updateUser/{userid}")
    @ResponseBody
    public UserInfo updateUserInfo(@PathVariable("userid") int userid,@RequestBody UserInfo userInfo){
        System.out.println(userid);
        System.out.println(userInfo);
        return  userInfo;
    }

    @ApiOperation("用户信息删除")
    @DeleteMapping("/delteUser/{userid}")
    @ResponseBody
    public void deleteUserInfo(@PathVariable("userid") int userid){
        System.out.println(userid);
    }

}
